package com.suxin.security.builder;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author Tang
 * @classname AbstractSecurityBuilder
 * @description [  ]
 * @date 2022/8/16 15:56
 */
public abstract class AbstractSecurityBuilder<O> implements SecurityBuilder<O> {

    private final AtomicBoolean building = new AtomicBoolean(false);

    private O object;

    @Override
    public O builder() throws Exception {
        if (this.building.compareAndSet(false, true)) {
            this.object = doBuilder();
            return this.object;
        }
        return this.object;
    }

    /**
     * doBuilder
     * @return O
     */
    public abstract O doBuilder() throws Exception;
}
